Skip to content

fix(plugin-chatbot): bold next to CJK full-width punctuation renders bold - #34079

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-agxd8a
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/project-thread-agxd8a

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Fixes #33723

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:聊天回答和推理面板里,中文字紧贴 **、另一侧是全角标点(《》「」,。!?、)时,粗体不再显示成字面星号;做法是给 streamdown 的 cjk 插槽接上 remark-cjk-friendly(新增一个 MIT 依赖,只取解析半边)。
  • 为什么改:CommonMark 把全角标点当标点,中文句子里 ** 两侧没有空格,定界符判不成开/闭;卡上原例「《书名》,借书人」单独渲染本来就是粗体,真正坏的是 借书人是**《书名》**的作者 这类「中文字 + ** + 全角标点」。
  • 风险与回滚:只影响聊天 markdown 的强调解析;ASCII 粗体、行内代码、反斜杠转义保持 CommonMark 原义(有钉子);新依赖让聊天 bundle 增加约 5.6 KB gzip;回滚即 revert 本 PR。
  • 先看:ui/packages/plugin-chatbot/src/chatMarkdownPlugins.ts(插件配置与理由)、ui/packages/plugin-chatbot/src/elements/message.tsx(调用方自带 plugins 时仍保留 CJK 规则的合并)、pnpm-lock.yaml(只增不改)。
  • 两分钟验证:pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/chatAnswerLayout-13032.test.tsx,预期 29 条全绿。
  • 需要你做的:无,席位落地。

What changes

  • @object-ui/plugin-chatbot adds the dependency remark-cjk-friendly ^2.3.4 and imports its parseOnly entry.
  • A new module, src/chatMarkdownPlugins.ts, exports CHAT_MARKDOWN_PLUGINS: a streamdown PluginConfig whose cjk slot carries the plugin in remarkPluginsBefore, so it runs before remark-gfm and owns the emphasis tokenizer.
  • Both chat markdown call sites render with that one constant, so they cannot drift:
    • MessageResponse (src/elements/message.tsx) passes plugins={{ ...CHAT_MARKDOWN_PLUGINS, ...plugins }}. A caller that passes its own plugins keeps the CJK rule unless it sets cjk itself.
    • ReasoningContent (src/elements/reasoning.tsx) passes plugins={CHAT_MARKDOWN_PLUGINS}.
  • The module lives in src/, not src/elements/. src/elements/ is the vendored directory that scripts/check-spec-symbol-derivation.mjs skips, and the package test "the vendored directory stays vendored" refuses a file there with no vendor banner.
  • pnpm-lock.yaml only gains lines for the new package and its transitive deps. No existing resolution moves.

Why

Card premise, corrected. The card's example on its own already renders bold on origin/main (fb79d47c, streamdown 2.5.0, read with react-dom/server): in 「**《书名》,借书人**」 the opener follows 「, which is punctuation, so the run is left-flanking. The defect is a CJK letter beside the delimiter, with full-width punctuation on the other side:

  • 借书人是**《书名》**的作者: the opener follows a letter and precedes 《, so it is not left-flanking.
  • 他说**你好,**我们走: the closer follows , and precedes a letter, so it is not right-flanking.

CommonMark counts full-width punctuation as punctuation, and a CJK sentence puts no space beside the run, so both stay literal asterisks. remark-cjk-friendly implements the markdown-cjk-friendly rule, which reads a CJK character beside the run the way it reads the whitespace an English sentence would have there.

Dependency choice

The tree had nothing CJK-aware (remark-gfm 4.0.1, micromark 4.0.2), and streamdown's plugins.cjk slot was empty. The seat chose A from three options.

  • A, taken: remark-cjk-friendly ^2.3.4, MIT. It fixes emphasis at the tokenizer (a micromark extension). Its parseOnly entry pulls in micromark-extension-cjk-friendly 2.0.2 (MIT), micromark-extension-cjk-friendly-util 3.0.1 (MIT) and get-east-asian-width 1.6.0 (MIT). The other micromark utilities it needs were already in the tree. The lockfile also records the unused serializer half (mdast-util-to-markdown-cjk-friendly 1.0.2, mdast-util-to-markdown 2.2.3), because the package declares it. The chat never imports that half, so it is not bundled.
  • B, not taken: @streamdown/cjk 1.0.4, Apache-2.0. It is A plus CJK strikethrough and autolink-boundary splitting, which is more surface than the card asks for.
  • C, not taken: a hand-written mdast post-step that re-pairs literal ** in text nodes. After parsing, an escaped \*\* and a failed delimiter are the same text, so this step would bold escaped asterisks. It is a workaround, not the root fix.

Bundle cost was measured with esbuild (minify, ESM, browser) on streamdown with and without the import, with react, mermaid and shiki external:

entry added, raw added, gzip -9
remark-cjk-friendly/parseOnly (shipped) 15,399 B 5,580 B
remark-cjk-friendly (both halves, not shipped) 40,893 B 13,569 B

In the Console, the micromark…/remark-… modules match the vendor-markdown group in apps/console/vite.config.ts. That group is tagged $initial. The eager-closure ceiling (ui/scripts/check-eager-closure-budget.mjs) is judged in CI by the Build & E2E UI job. It was not measured locally, because a full Console build was out of scope for this card.

Tests

Pins go in the existing MessageResponse harness, src/__tests__/chatAnswerLayout-13032.test.tsx, as a new top-level describe: "bold next to CJK full-width punctuation (objectstack#33723)". No existing test was edited.

  • Reds that turn green (8): an opener after a CJK letter, before 《 and before 「; a closer after , 。 ! ? 、 」, each before a CJK letter.
  • Controls that were already bold (8): the card's own example 「**《书名》,借书人**」; bold ending before , 。 ! ? 、 」; bold starting after 「.
  • CommonMark controls, unchanged (4): ASCII emphasis (**bold**, foo**bar**baz); a**"b"**c stays literal, as CommonMark says; escaped \*\*《书名》\*\* stays literal; ** inside an inline code span stays literal.
  • Wiring (2): a caller's own plugins keeps the CJK rule; the reasoning panel renders with the same rule.
Ablation: remove the plugin from CHAT_MARKDOWN_PLUGINS

node scripts/ablation-replace.mjs --file ui/packages/plugin-chatbot/src/elements/markdown-plugins.ts --anchor 'PluginConfig = { cjk: CJK_EMPHASIS };' --replacement 'PluginConfig = { /* ablated */ };'. This ran on commit 8bc8bf07, before the module moved to src/. The ui vitest resolves @object-ui/* to source, so no build is needed between the mutation and the run.

ablation-replace: ok mutation landed: anchor 1 -> 0, blob df1179302ec9 -> be3bf7e3e506
 Test Files  1 failed (1)
      Tests  10 failed | 19 passed (29)
ablation-replace: ok restored: blob == HEAD (df1179302ec9) and `git diff HEAD` is empty

The 10 reds are exactly the 8 failing cases plus the 2 wiring pins. All 19 controls stayed green.

Runs at head ac2b0a1
pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/spec-symbol-batch6.test.ts packages/plugin-chatbot/src/__tests__/chatAnswerLayout-13032.test.tsx
 Test Files  2 passed (2)
      Tests  51 passed (51)
os-verify-lock: VERDICT command-exit 0

pnpm --dir ui exec vitest run packages/plugin-chatbot/   (at 378a8dc2, before the move out of src/elements/)
 Test Files  1 failed | 100 passed (101)
      Tests  1 failed | 1006 passed (1007)
   the one red: "the vendored directory stays vendored > markdown-plugins.ts is upstream, not ours",
   which the move to src/chatMarkdownPlugins.ts (ac2b0a14) fixes; that file is green in the run above

pnpm --filter @object-ui/plugin-chatbot type-check
os-verify-lock: VERDICT command-exit 0

pnpm exec eslint (the four touched source files)
✖ 6 problems (0 errors, 6 warnings), all on lines this diff does not touch

Acceptance notes

  • ui/packages/plugin-chatbot/README.md › "Bundle considerations" lists the package's markdown dependencies (streamdown, shiki, mermaid, katex) and does not name the new small parser extension. It was left as is because the section is about the heavy chunks.
  • The eslint warnings on message.tsx and reasoning.tsx are all on lines this diff does not touch (0 errors).
  • The real-browser chat-panel check that the delta lists as optional was not run.

Verification

Local gates: node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, run at head ac2b0a14, each command's exit code captured before any pipe, then reconciled with --ran:

Run reconciliation — 59 derived, 58 run, 1 NOT-MEASURED, 0 UNRUN.
✓ dispatch-gates --ran: 59 derived famil(ies) accounted for — 58 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3).
  • 58 of 59 exited 0. That includes pnpm --dir ui exec vitest run scripts/ (Test Files 171 passed, 2 skipped; Tests 5065 passed, 2 skipped), check:undeclared-dep-imports, check:override-consistency, check-osv-exemptions, check-empty-changeset --base origin/main, check-changeset-no-major and check:changeset-fixed.
  • NOT MEASURED: check:dual-build-cjs-loads. It reported PREREQUISITE NOT MET (exit 3) because it reads the built dist/ of every dual-build @objectstack/* package, and this container did not build them. The lockfile is the only path that derives this family, and the lockfile change adds packages to @object-ui/plugin-chatbot alone. CI's Lint & Repo Gates job runs it.
  • pnpm check:new-line-citations (ui): 0 new citations.
  • Not re-run after the derivation: the tree is 5 commits behind origin/main. None of those commits touches ui/packages/plugin-chatbot/** or pnpm-lock.yaml. The derivation flagged it as STALE TREE.
  • CI-owned families (Test UI shards, Type Check UI, Build & E2E UI with the eager-closure budget) are judged on this PR's check-runs.

Generated by Claude Code

…bold

CommonMark's flanking rule reads full-width punctuation as punctuation, so
a ** run with a CJK letter on one side and full-width punctuation on the
other never opened or closed in chat answers. Every chat markdown surface
now renders with remark-cjk-friendly in streamdown's cjk slot, from one
shared constant.

Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq
Co-authored-by: Claude <noreply@anthropic.com>
… add the changeset

The chat renders markdown and never serializes it, so the parseOnly entry
keeps the markdown serializer out of the chatbot bundle.

Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq
Co-authored-by: Claude <noreply@anthropic.com>
…vendored elements directory

Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 15, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#1 · os-steve · session_01ADHkmT2NE3iyG1o6TDg3sf

席位核对

Verdict: ACCEPT · head ac2b0a14 · 2026-11-15T18:28Z

  1. Shape. Draft → main, first content line Fixes #33723. 7 files on the claimed surface (claim 6898286060, dependency approved by the seat in the card thread): ui/packages/plugin-chatbot/package.json (+remark-cjk-friendly ^2.3.4), new src/chatMarkdownPlugins.ts (one CHAT_MARKDOWN_PLUGINS constant), elements/message.tsx and elements/reasoning.tsx (both Streamdown call sites take it), one test file, pnpm-lock.yaml (+100/−0, add-only), one changeset (@object-ui/plugin-chatbot patch, names the new MIT dependency).
  2. Premise / root cause. Corrected by the dev and accepted: the card's own example already renders bold (「 before ** is punctuation, so flanking passes); the defect is a CJK letter beside a ** run whose other side is full-width punctuation. Root fix at the tokenizer (markdown-cjk-friendly rule), not a post-pass. Seat read of streamdown 2.5.0's dist: the cjk slot's remarkPluginsBefore runs ahead of remark-gfm and remarkPluginsAfter after it; the deprecated remarkPlugins field is type-required and not read, so the plugin is applied once. A caller's own plugins spread after the constant, so MessageResponse keeps the rule unless a caller overrides cjk on purpose.
  3. Contract. Clause-②: no, Metadata-protocol: none; no export moves, the new module is internal. Changeset patch is right. Dependency: MIT, parseOnly entry (+5,580 B gzip vs +13,569 B for the full entry); B (@streamdown/cjk) and C (mdast re-pairing, blind to escapes) were weighed and refused in the body.
  4. Gates on ac2b0a14. 59 check runs: 49 success, 10 skipped, none failed; Lint & Repo Gates, TypeScript Type Check, Test UI (16 shards) and Build & E2E UI (the eager-closure budget) all success, so the locally unmeasured check:dual-build-cjs-loads family is answered by CI.
  5. K. K = 10 first-parent commits on main (63db7240aa) since the merge base; < 15, no sync owed.
  6. Governed. check-governed-merges --pr 34079: NOT governed (0 of 7 paths).
  7. Deviations / notes. Locally 58 of 59 derived gates exit 0; check:dual-build-cjs-loads NOT MEASURED locally (exit 3, no dist in the container), judged by CI above; the eager-closure budget likewise by Build & E2E UI. Ablation (plugin removed): exactly the 10 CJK reds turn red, 19 controls stay green. Skills-docs: not owed.
  8. Landing. This stroke: pr_ready + automerge_enable, under the maintainer's landing approval in the seat thread (2026-11-15T16:10Z, 「批准席位 本班复核通过的 PR 执行 --land」). On MERGED the seat closes out Chat markdown: bold next to full-width punctuation renders as literal asterisks (「**《书名》,借书人**」) #33723.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 15, 2026 18:28
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 393a576 Nov 15, 2026
60 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-agxd8a branch November 15, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat markdown: bold next to full-width punctuation renders as literal asterisks (「**《书名》,借书人**」)

2 participants